package com.appliance.cycling2011.rsshandling;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;

public abstract class BaseFeedParser {

	// names of the XML tags
	static final String CHANNEL = "channel";
	static final String PUB_DATE = "pubDate";
	static final String DESCRIPTION = "description";
	static final String LINK = "link";
	static final String IMAGE = "image";
	static final String TITLE = "title";
	static final String ITEM = "item";
	static final String ENTRY = "entry";
	static final String UPDATED = "updated";
	static final String CONTENT = "content";

	private URL feedUrl;
	private String feedXml;

	protected BaseFeedParser(String feedUrl) {
		try {
			this.feedXml = feedUrl;
			if (feedUrl.contains("http")) {
				this.feedUrl = new URL(feedUrl);
			}
		} catch (MalformedURLException e) {
			throw new RuntimeException(e);
		}
	}

	protected InputStream getInputStream() {
		try {
			if (this.feedUrl != null) {
				return feedUrl.openConnection().getInputStream();
			} else {
				InputStream in = new FileInputStream(feedXml);
				return in;
			}

		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}
}